package com.easylive.admin.controller;

import com.easylive.entity.po.VideoComment;
import com.easylive.entity.po.VideoDanmu;
import com.easylive.entity.query.VideoCommentQuery;
import com.easylive.entity.query.VideoDanmuQuery;
import com.easylive.entity.vo.PaginationResultVO;
import com.easylive.entity.vo.ResponseVO;
import com.easylive.service.VideoCommentService;
import com.easylive.service.VideoDanmuService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * @Author: yudaxian
 * @DateTime: 2024/12/31 15:45
 **/
@RestController
@RequestMapping("/interact")
public class VideoInteractController extends ABaseController {

    @Resource
    private VideoCommentService videoCommentService;

    @Resource
    private VideoDanmuService videoDanmuService;

    @PostMapping("/loadComment")
    public ResponseVO loadComment(@Validated Integer pageNo, Integer pageSize, String videoNameFuzzy) {
        VideoCommentQuery commentQuery = new VideoCommentQuery();
        commentQuery.setPageSize(pageSize);
        commentQuery.setPageNo(pageNo);
        commentQuery.setOrderBy("post_time desc");
        commentQuery.setQueryVideoInfo(true);
        commentQuery.setVideoNameFuzzy(videoNameFuzzy);
        PaginationResultVO<VideoComment> page = videoCommentService.findListByPage(commentQuery);

        return getSuccessResponseVO(page);
    }

    @PostMapping("/delComment")
    public ResponseVO delComment(@Validated @NotNull Integer commentId) {
        videoCommentService.deleteVideoCommentByCommentIdOrPcommentId(commentId);
        return getSuccessResponseVO(null);
    }

    @PostMapping("/loadDanmu")
    public ResponseVO loadDanmu(@Validated Integer pageNo, Integer pageSize, String videoNameFuzzy) {
        VideoDanmuQuery danmuQuery = new VideoDanmuQuery();
        danmuQuery.setPageSize(pageSize);
        danmuQuery.setPageNo(pageNo);
        danmuQuery.setOrderBy("post_time desc");
        danmuQuery.setQueryUserInfo(true);
        danmuQuery.setQueryVideoInfo(true);
        danmuQuery.setVideoNameFuzzy(videoNameFuzzy);
        PaginationResultVO<VideoDanmu> page = videoDanmuService.findListByPage(danmuQuery);

        return getSuccessResponseVO(page);
    }

    @PostMapping("/delDanmu")
    public ResponseVO delDanmu(@Validated @NotNull Integer danmuId) {
        videoDanmuService.deleteVideoDanmuByDanmuId(danmuId);
        return getSuccessResponseVO(null);
    }

}
